<!DOCTYPE html>
<html lang="zh">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimal-ui">
    <title>修改密码</title>
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-touch-fullscreen" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="default">
    <script type="text/javascript" src="/statics/js/custom/base.js"></script>

</head>

<body>
<div class="container-fluid p-t-15">
    <div class="row">
        <div class="col-lg-12">
            <div class="card">
                <div class="card-body">
                    <form method="post" action="" id="passwordForm">
                        <div class="mb-3  mx_validator">
                            <label for="old_pwd" class="form-label">旧密码</label>
                            <input type="password" class="form-control mx_required" id="old_pwd"
                                   name="oldPassword" mx_required_msg="旧密码不能为空"
                                   placeholder="旧密码"/>
                        </div>
                        <div class="mb-3  mx_validator">
                            <label for="new_pwd" class="form-label">新密码</label>
                            <input type="password" class="form-control mx_required mx_custom"
                                   mx_required_msg="新密码不能为空" id="new_pwd" name="newPassword"
                                   placeholder="新密码"/>
                        </div>
                        <div class="mb-3  mx_validator">
                            <label for="confirm_pwd" class="form-label">确认新密码</label>
                            <input type="password" class="form-control mx_required mx_custom"
                                   mx_required_msg="确认新密码不能为空" id="confirm_pwd" name="rePassword"
                                   placeholder="确认新密码"/>
                        </div>
                        <button type="button" class="btn btn-primary mx_validator_button" id="submit">保存
                        </button>
                    </form>

                </div>
            </div>
        </div>

    </div>
</div>


<script type="text/javascript">

    function customValidate() {
        var result = {
            "retBool": false,
            "msg": ""
        };
        var data = Form.getValues($("#passwordForm"));
        if (data.newPassword !== data.rePassword) {
            result = {
                "retBool": true,
                "msg": "两次密码输入不一致"
            };
        }
        return result;
    }

    $(function () {
        $("#submit").click(function () {

            Validator.builder()
                .dom($("#passwordForm"))
                .url(ADMIN_UPDATE_PASSWORD)
                .customValidate(customValidate)
                .submitCallback(function (e) {
                    if (e.code === "00000") {
                        LayerUtil.successMsg(ERROR_MSG.SUCCESS)
                        setTimeout(function () {
                            Token.remove();
                            Menu.remove()
                            Menu.removePermission();
                            User.remove()
                            window.location.href = LOGIN_VIEW;
                        }, 1000)
                    } else {
                        $(".mx_validator_button").attr("disabled", false)
                        LayerUtil.failMsg(e.msg != null ? e.msg : ERROR_MSG.FAIL)
                    }
                })
                .do();
        });
    });


</script>
</body>
</html>
